#include<iostream>
#include<cstring>
using namespace std;
int n,k;
int pct[101][101];

int prim(){
	int minn[101]={0};
	bool vis[101]={0};
	int mst=0;
	
	memset(minn,0x3f,4*n+4);
	minn[1]=0;
	for(int i=1;i<=n;i++){
		int wp=0;
		for(int i=1;i<=n;i++){
			if(vis[i]) continue;
			if(wp==0||minn[wp]>minn[i])
				wp=i;
		}
		vis[wp]=1;
		mst+=minn[wp];
		for(int i=1;i<=n;i++){
			if(vis[i]) continue;
			if(pct[wp][i]==0) continue;
			if(minn[i]>pct[wp][i]){
				minn[i]=pct[wp][i];
			}
		}
	}
	
	return mst;
}

int main(){
	cin>>n>>k;
	int sum=0;
	for(int i=1,x,y,z;i<=k;i++){
		cin>>x>>y>>z;
		pct[x][y]=pct[y][x]=z;
		sum+=z;
	}
	int value=prim();
	cout<<sum-value;
	return 0;
} 
